package com.java110.mall.cart.bmo.businessQuery.impl;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.product.ProductSeckillDto;
import com.java110.dto.product.ProductSeckillOrderDto;
import com.java110.intf.goods.IProductSeckillOrderV1InnerServiceSMO;
import com.java110.intf.goods.IProductSeckillV1InnerServiceSMO;
import com.java110.mall.cart.bmo.businessQuery.IBusinessQuerySeckill;
import com.java110.utils.util.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessQuerySeckillImpl implements IBusinessQuerySeckill {

    @Autowired
    private IProductSeckillV1InnerServiceSMO productSeckillV1InnerServiceSMOImpl;

    @Autowired
    private IProductSeckillOrderV1InnerServiceSMO productSeckillOrderV1InnerServiceSMOImpl;

    @Override
    public void querySecKillByGoodsName(JSONObject reqJson, String searchValue, String shopId, List<ProductSeckillDto> allProductSeckillDtos) {

        ProductSeckillDto productSeckillDto = new ProductSeckillDto();
        productSeckillDto.setShopId(shopId);
        productSeckillDto.setProdNameLike(searchValue);
        productSeckillDto.setPage(1);
        productSeckillDto.setRow(10);
        List<ProductSeckillDto> productSeckillDtos = productSeckillV1InnerServiceSMOImpl.queryProductSeckills(productSeckillDto);
        if(ListUtil.isNull(productSeckillDtos)){
            return ;
        }
        allProductSeckillDtos.addAll(productSeckillDtos);
    }

    @Override
    public void querySecKillByProductId(JSONObject reqJson, String searchValue, String shopId, List<ProductSeckillDto> allProductSeckillDtos) {
        ProductSeckillDto productSeckillDto = new ProductSeckillDto();
        productSeckillDto.setShopId(shopId);
        productSeckillDto.setProductId(searchValue);
        productSeckillDto.setPage(1);
        productSeckillDto.setRow(10);
        List<ProductSeckillDto> productSeckillDtos = productSeckillV1InnerServiceSMOImpl.queryProductSeckills(productSeckillDto);
        if(ListUtil.isNull(productSeckillDtos)){
            return ;
        }
        allProductSeckillDtos.addAll(productSeckillDtos);
    }

    @Override
    public void querySeckillOrderByKillId(JSONObject reqJson, String killId, String shopId, List<ProductSeckillOrderDto> allProductSeckillOrderDtos) {

        ProductSeckillOrderDto productSeckillOrderDto = new ProductSeckillOrderDto();
        productSeckillOrderDto.setKillId(killId);
        productSeckillOrderDto.setShopId(shopId);
        productSeckillOrderDto.setPage(1);
        productSeckillOrderDto.setRow(10);
        List<ProductSeckillOrderDto> productSeckillOrderDtos = productSeckillOrderV1InnerServiceSMOImpl.queryProductSeckillOrders(productSeckillOrderDto);
        if(ListUtil.isNull(productSeckillOrderDtos)){
            return ;
        }
        allProductSeckillOrderDtos.addAll(productSeckillOrderDtos);
    }
}
